package com.ymanage.util;

import java.util.List;

/**
 * 分页数据类
 * @author Alen
 * Page分页工具类：用于数据的分页
 * 根据传入的pageNum参数来确定从哪页开始分页
 * 根据传入的size参数确定每页分多少条记录
 * 根据传入的rowCount参数来确定数据总条数
 */
public class Page {
		
	private int pageNum;			//当前页码
	private int size;				//页面大小
	private int rowCount;			//从DB中得到数据总数
	private String url;				//请求路径和参数，例如：/BookServlet?method=findXXX&cid=1&bname=2
	
	private List list;				//数据集合
	
	/*由以上属性得到以下数据*/
	private int pageCount;			//总页数	
	private int first=1;			//第一页
	private int last;				//最后一页
	private int prev;  				//前一页  页号
	private int next;  				//后一页  页号
	
	

	/*构造器*/
	public Page(int pageNum,int size,int rowCount){
		
		//初始化基本参数
		this.pageNum = pageNum;
		this.size = size;
		this.rowCount = rowCount;
		
		/*计算得到其他参数*/
		//计算得到页面总数
		if(rowCount%size ==0 ){
			this.pageCount = rowCount/size;
		}else{
			this.pageCount = (rowCount/size)+1;
		}
		
		this.last = pageCount;
		
		//判断当前页码是否超出页码范围
		if(pageNum<1){
			pageNum=1;
		}else if(pageNum>pageCount){
			pageNum=pageCount;
		}
		
		//如果<前一页>为第一页，则显示1,否则是{本页页数-1}
		this.prev = (this.pageNum-1>1)?(this.pageNum-1):1;  
		//如果<后一页>为最后一页，则返回{最后一页页数}，否则返回{本页数+1}
		this.next = (this.pageNum+1<this.pageCount)?(this.pageNum+1):this.pageCount;  
	}
	
	/*无参构造*/
	public Page(){
		
	}

	/*get、set方法*/
	
	public int getPrev() {
		return prev;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public void setPrev(int prev) {
		this.prev = prev;
	}

	public int getNext() {
		return next;
	}

	public void setNext(int next) {
		this.next = next;
	}
	
	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public int getRowCount() {
		return rowCount;
	}

	public void setRowCount(int rowCount) {
		this.rowCount = rowCount;
	}

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getFirst() {
		return first;
	}

	public void setFirst(int first) {
		this.first = first;
	}

	public int getLast() {
		return last;
	}

	public void setLast(int last) {
		this.last = last;
	}
	
		
}
